package com.example.gulimallproduct.controller;

import java.util.Arrays;

import com.example.gulimallproduct.request.SelectSpuOrSkuInfoPageRequest;
import com.example.gulimallproduct.vo.SavePruductSpuinfoVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.example.gulimallproduct.entity.SpuInfoEntity;
import com.example.gulimallproduct.service.SpuInfoService;
import com.example.common.utils.R;



/**
 * spu信息
 *
 * @author zzl
 * @email zzl@gmail.com
 * @date 2025-10-24 15:22:38
 */
@RestController
@RequestMapping("/spuinfo")
public class SpuInfoController {
    private static final Logger log = LoggerFactory.getLogger(SpuInfoController.class);
    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@Validated SelectSpuOrSkuInfoPageRequest selectSpuOrSkuInfoPageRequest){
//        PageUtils page = spuInfoService.queryPage(params);
        log.info("查询商品列表:{}", selectSpuOrSkuInfoPageRequest);
        return spuInfoService.selectSpuInfo(selectSpuOrSkuInfoPageRequest);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		SpuInfoEntity spuInfo = spuInfoService.getById(id);

        return R.ok().put("spuInfo", spuInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody SavePruductSpuinfoVO spuInfo){
        log.info("保存商品:{}", spuInfo);
        return spuInfoService.saveSpuInfo(spuInfo);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody SpuInfoEntity spuInfo){
		spuInfoService.updateById(spuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		spuInfoService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
